<?php $GLOBALS['_beginTime'] = microtime(TRUE);
if (!defined('APP_DEBUG')) define('APP_DEBUG', 0);
if (!defined('BUILD_DIR_SECURE')) define('BUILD_DIR_SECURE', true);
if (!defined('APP_PATH')) define('APP_PATH', '/mnt/d/Code/php/TP-Fenxi/');
if (!defined('TPCORE_PATH')) define('TPCORE_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/');
if (!defined('RUNTIME_PATH')) define('RUNTIME_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Runtime/');
if (!defined('RUNTIME_FILE')) define('RUNTIME_FILE', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Runtime/~runtime.php');
if (!defined('TPFRAMEWORK')) define('TPFRAMEWORK', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/TpFramework/');
if (!defined('CORE_PATH')) define('CORE_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Lib/');
if (!defined('EXTEND_PATH')) define('EXTEND_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Extend/');
if (!defined('MODE_PATH')) define('MODE_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Extend/Mode/');
if (!defined('ENGINE_PATH')) define('ENGINE_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Extend/Engine/');
if (!defined('VENDOR_PATH')) define('VENDOR_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Extend/Vendor/');
if (!defined('LIBRARY_PATH')) define('LIBRARY_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Extend/Library/');
if (!defined('COMMON_PATH')) define('COMMON_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/TpFramework/Common/');
if (!defined('LIB_PATH')) define('LIB_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/TpFramework/Lib/');
if (!defined('CONF_PATH')) define('CONF_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/TpFramework/Conf/');
if (!defined('LANG_PATH')) define('LANG_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/TpFramework/Lang/');
if (!defined('TMPL_PATH')) define('TMPL_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/TpFramework/Tpl/');
if (!defined('HTML_PATH')) define('HTML_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/TpFramework/Html/');
if (!defined('LOG_PATH')) define('LOG_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Runtime/Logs/');
if (!defined('TEMP_PATH')) define('TEMP_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Runtime/Temp/');
if (!defined('DATA_PATH')) define('DATA_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Runtime/Data/');
if (!defined('CACHE_PATH')) define('CACHE_PATH', '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Runtime/Cache/');
function jichulei()
{
    echo "caonima";
}

class Think
{
    private static $_instance = array();

    static public function Start()
    {
        Think::buildApp();
        return;
    }

    static private function buildApp()
    {
        C(include TPCORE_PATH . 'Conf/convention.php');
        L(include TPCORE_PATH . 'Lang/' . strtolower(C('DEFAULT_LANG')) . '.php');
        if (is_file(CONF_PATH . 'config.php')) C(include CONF_PATH . 'config.php');
        if (defined('MODE_NAME')) {
            $mode = include MODE_PATH . strtolower(MODE_NAME) . '.php';
        } else {
            $mode = array();
        }
        if (isset($mode['config'])) {
            C(is_array($mode['config']) ? $mode['config'] : include $mode['config']);
        }
        if (C('APP_TAGS_ON')) {
            if (isset($mode['extends'])) {
                C('extends', is_array($mode['extends']) ? $mode['extends'] : include $mode['extends']);
            } else {
                C('extends', include TPCORE_PATH . 'Conf/tags.php');
            }
        }
        if (isset($mode['tags'])) {
            C('tags', is_array($mode['tags']) ? $mode['tags'] : include $mode['tags']);
        } elseif (is_file(CONF_PATH . 'tags.php')) {
            C('tags', include CONF_PATH . 'tags.php');
        }
        $compile = '';
        $tptool = APP_PATH . "TpTool.php";
        if (!APP_DEBUG) $compile .= compile($tptool);
        if (isset($mode['core'])) {
            $list = $mode['core'];
        } else {
            $list = array(TPCORE_PATH . 'Common/functions.php', CORE_PATH . 'Core/Log.class.php', CORE_PATH . 'Core/Dispatcher.class.php', CORE_PATH . 'Core/App.class.php', CORE_PATH . 'Core/Action.class.php', CORE_PATH . 'Core/View.class.php',);
        }
        if (is_file(CONF_PATH . 'core.php')) {
            $list = array_merge($list, include CONF_PATH . 'core.php');
        }
        foreach ($list as $file) {
            if (is_file($file)) {
                require_cache($file);
                if (!APP_DEBUG) $compile .= compile($file);
            }
        }
        if (is_file(COMMON_PATH . 'common.php')) {
            include COMMON_PATH . 'common.php';
            if (!APP_DEBUG) $compile .= compile(COMMON_PATH . 'common.php');
        }
        if (isset($mode['alias'])) {
            $alias = is_array($mode['alias']) ? $mode['alias'] : include $mode['alias'];
            alias_import($alias);
            if (!APP_DEBUG) $compile .= 'alias_import(' . var_export($alias, true) . ');';
        }
        if (is_file(CONF_PATH . 'alias.php')) {
            $alias = include CONF_PATH . 'alias.php';
            alias_import($alias);
            if (!APP_DEBUG) $compile .= 'alias_import(' . var_export($alias, true) . ');';
        }
        if (APP_DEBUG) {
            C(include THINK_PATH . 'Conf/debug.php');
            $status = C('APP_STATUS');
            if (is_file(CONF_PATH . $status . '.php')) C(include CONF_PATH . $status . '.php');
        } else {
            build_runtime_cache($compile);
        }
        return;
    }
}

Class CheckLang
{
}

alias_import(array('Model' => '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Lib/Core/Model.class.php', 'Db' => '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Lib/Core/Db.class.php', 'Log' => '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Lib/Core/Log.class.php', 'ThinkTemplate' => '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Lib/Template/ThinkTemplate.class.php', 'TagLib' => '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Lib/Template/TagLib.class.php', 'Cache' => '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Lib/Core/Cache.class.php', 'Widget' => '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Lib/Core/Widget.class.php', 'TagLibCx' => '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Lib/Driver/TagLib/TagLibCx.class.php',));
function load_runtime_file()
{
    require TPCORE_PATH . 'Common/common.php';
    $list = array(CORE_PATH . 'Core/Think.class.php', CORE_PATH . 'Core/ThinkException.class.php', CORE_PATH . 'Core/Behavior.class.php',);
    foreach ($list as $key => $file) {
        if (is_file($file)) require_cache($file);
    }
    alias_import(include TPFRAMEWORK . 'Conf/alias.php');
    if (!is_dir(LIB_PATH)) {
        build_app_dir();
    } elseif (!is_dir(CACHE_PATH)) {
        check_runtime();
    } elseif (APP_DEBUG) {
        if (is_file(RUNTIME_FILE)) unlink(RUNTIME_FILE);
    }
}

function build_runtime_cache($append = '')
{
    $defs = get_defined_constants(TRUE);
    $content = '$GLOBALS[\'_beginTime\'] = microtime(TRUE);';
    if (defined('RUNTIME_DEF_FILE')) {
        file_put_contents(RUNTIME_DEF_FILE, '<?php ' . array_define($defs['user']));
        $content .= 'require \'' . RUNTIME_DEF_FILE . '\';';
    } else {
        $content .= array_define($defs['user']);
    }
    $list = array(TPCORE_PATH . 'Common/common.php', CORE_PATH . 'Core/Think.class.php', CORE_PATH . 'Core/ThinkException.class.php', CORE_PATH . 'Core/Behavior.class.php',);
    foreach ($list as $file) {
        $content .= compile($file);
    }
    if (C('APP_TAGS_ON')) {
        $content .= build_tags_cache();
    }
    $alias = include TPCORE_PATH . 'Conf/alias.php';
    $content .= 'alias_import(' . var_export($alias, true) . ');';
    $content .= $append . "\nL(" . var_export(L(), true) . ");C(" . var_export(C(), true) . ');G(\'loadTime\');Think::Start();';
    file_put_contents(RUNTIME_FILE, strip_whitespace('<?php ' . $content));
}

function build_tags_cache()
{
    $tags = C('extends');
    $content = '';
    foreach ($tags as $tag => $item) {
        foreach ($item as $key => $name) {
            $content .= is_int($key) ? compile(CORE_PATH . 'Behavior/' . $name . 'Behavior.class.php') : compile($name);
        }
    }
    return $content;
}

function build_app_dir()
{
    if (!is_dir(APP_PATH)) mk_dir(APP_PATH, 0777);
    if (is_writeable(APP_PATH)) {
        $dirs = array(LIB_PATH, RUNTIME_PATH, CONF_PATH, COMMON_PATH, LANG_PATH, CACHE_PATH, TMPL_PATH, TMPL_PATH . C('DEFAULT_THEME') . '/', LOG_PATH, TEMP_PATH, DATA_PATH, LIB_PATH . 'Model/', LIB_PATH . 'Action/', LIB_PATH . 'Behavior/', LIB_PATH . 'Widget/',);
        foreach ($dirs as $dir) {
            if (!is_dir($dir)) mk_dir($dir, 0777);
        }
        defined('BUILD_DIR_SECURE') or define('BUILD_DIR_SECURE', false);
        if (BUILD_DIR_SECURE) {
            defined('DIR_SECURE_FILENAME') or define('DIR_SECURE_FILENAME', 'index.html');
            defined('DIR_SECURE_CONTENT') or define('DIR_SECURE_CONTENT', 'hello  这是tonicgb生成的');
            $content = DIR_SECURE_CONTENT;
            $a = explode(',', DIR_SECURE_FILENAME);
            foreach ($a as $filename) {
                foreach ($dirs as $dir) file_put_contents($dir . $filename, $content);
            }
        }
        if (!is_file(CONF_PATH . 'config.php')) file_put_contents(CONF_PATH . 'config.php', "<?php\nreturn array(\n\t//'配置项'=>'配置值'\n);\n?>");
        if (!is_file(LIB_PATH . 'Action/IndexAction.class.php')) build_first_action();
    } else {
        header('Content-Type:text/html; charset=utf-8');
        exit('项目目录不可写，目录无法自动生成！<BR>请使用项目生成器或者手动生成项目目录~');
    }
}

function build_first_action()
{
    $content = file_get_contents(TPCORE_PATH . 'Tpl/default_index.tpl');
    file_put_contents(LIB_PATH . 'Action/IndexAction.class.php', $content);
}

function array_define($array, $check = true)
{
    $content = "\n";
    foreach ($array as $key => $val) {
        $key = strtoupper($key);
        if ($check) $content .= 'if(!defined(\'' . $key . '\')) ';
        if (is_int($val) || is_float($val)) {
            $content .= "define('" . $key . "'," . $val . ");";
        } elseif (is_bool($val)) {
            $val = ($val) ? 'true' : 'false';
            $content .= "define('" . $key . "'," . $val . ");";
        } elseif (is_string($val)) {
            $content .= "define('" . $key . "','" . addslashes($val) . "');";
        }
        $content .= "\n";
    }
    return $content;
}

function check_runtime()
{
    if (!is_dir(RUNTIME_PATH)) {
        mkdir(RUNTIME_PATH, 0777);
    } elseif (!is_writeable(RUNTIME_PATH)) {
        header('Content-Type:text/html; charset=utf-8');
        exit('目录 [ ' . RUNTIME_PATH . ' ] 不可写！');
    }
    if (!is_dir(LOG_PATH)) mkdir(CACHE_PATH, 0777);
    if (!is_dir(LOG_PATH)) mkdir(LOG_PATH, 0777);
    if (!is_dir(TEMP_PATH)) mkdir(TEMP_PATH, 0777);
    if (!is_dir(DATA_PATH)) mkdir(DATA_PATH, 0777);
    return true;
}

alias_import(array('tonicgb_bieming' => '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Core/Lib/Core/Model.class.php',));
L(array('_MODULE_NOT_EXIST_' => '无法加载模块', '_ERROR_ACTION_' => '非法操作', '_LANGUAGE_NOT_LOAD_' => '无法加载语言包', '_TEMPLATE_NOT_EXIST_' => '模板不存在', '_MODULE_' => '模块', '_ACTION_' => '操作', '_ACTION_NOT_EXIST_' => '控制器不存在或者没有定义', '_MODEL_NOT_EXIST_' => '模型不存在或者没有定义', '_VALID_ACCESS_' => '没有权限', '_XML_TAG_ERROR_' => 'XML标签语法错误', '_DATA_TYPE_INVALID_' => '非法数据对象！', '_OPERATION_WRONG_' => '操作出现错误', '_NOT_LOAD_DB_' => '无法加载数据库', '_NOT_SUPPORT_DB_' => '系统暂时不支持数据库', '_NO_DB_CONFIG_' => '没有定义数据库配置', '_NOT_SUPPERT_' => '系统不支持', '_CACHE_TYPE_INVALID_' => '无法加载缓存类型', '_FILE_NOT_WRITEABLE_' => '目录（文件）不可写', '_METHOD_NOT_EXIST_' => '您所请求的方法不存在！', '_CLASS_NOT_EXIST_' => '实例化一个不存在的类！', '_CLASS_CONFLICT_' => '类名冲突', '_TEMPLATE_ERROR_' => '模板引擎错误', '_CACHE_WRITE_ERROR_' => '缓存文件写入失败！', '_TAGLIB_NOT_EXIST_' => '标签库未定义', '_OPERATION_FAIL_' => '操作失败！', '_OPERATION_SUCCESS_' => '操作成功！', '_SELECT_NOT_EXIST_' => '记录不存在！', '_EXPRESS_ERROR_' => '表达式错误', '_TOKEN_ERROR_' => '表单令牌错误', '_RECORD_HAS_UPDATE_' => '记录已经更新', '_NOT_ALLOW_PHP_' => '模板禁用PHP代码',));
C(array('default_theme' => '', 'app_tags_on' => true, 'default_lang' => 'zh-cn', 'app_status' => 'debug', 'app_file_case' => false, 'app_autoload_path' => '', 'app_sub_domain_deploy' => false, 'app_sub_domain_rules' => array(), 'app_sub_domain_deny' => array(), 'app_group_list' => '', 'cookie_expire' => 3600, 'cookie_domain' => '', 'cookie_path' => '/', 'cookie_prefix' => '', 'default_app' => '@', 'default_group' => 'Home', 'default_module' => 'Index', 'default_action' => 'index', 'default_charset' => 'utf-8', 'default_timezone' => 'PRC', 'default_ajax_return' => 'JSON', 'default_filter' => 'htmlspecialchars', 'db_type' => 'mysql', 'db_host' => 'localhost', 'db_name' => '', 'db_user' => 'root', 'db_pwd' => '', 'db_port' => '', 'db_prefix' => 'think_', 'db_fieldtype_check' => false, 'db_fields_cache' => true, 'db_charset' => 'utf8', 'db_deploy_type' => 0, 'db_rw_separate' => false, 'db_master_num' => 1, 'db_sql_build_cache' => false, 'db_sql_build_queue' => 'file', 'db_sql_build_length' => 20, 'data_cache_time' => 0, 'data_cache_compress' => false, 'data_cache_check' => false, 'data_cache_type' => 'File', 'data_cache_path' => '/mnt/d/Code/php/TP-Fenxi/tpDebugMode/Runtime/Temp/', 'data_cache_subdir' => false, 'data_path_level' => 1, 'error_message' => '您浏览的页面暂时发生了错误！请稍后再试～', 'error_page' => '', 'show_error_msg' => false, 'log_record' => false, 'log_type' => 3, 'log_dest' => '', 'log_extra' => '', 'log_level' => 'EMERG,ALERT,CRIT,ERR', 'log_file_size' => 2097152, 'log_exception_record' => false, 'session_auto_start' => true, 'session_options' => array(), 'session_type' => '', 'session_prefix' => '', 'var_session_id' => 'session_id', 'tmpl_content_type' => 'text/html', 'tmpl_action_error' => 'THINK_PATHTpl/dispatch_jump.tpl', 'tmpl_action_success' => 'THINK_PATHTpl/dispatch_jump.tpl', 'tmpl_exception_file' => 'THINK_PATHTpl/think_exception.tpl', 'tmpl_detect_theme' => false, 'tmpl_template_suffix' => '.html', 'tmpl_file_depr' => '/', 'url_case_insensitive' => false, 'url_model' => 1, 'url_pathinfo_depr' => '/', 'url_pathinfo_fetch' => 'ORIG_PATH_INFO,REDIRECT_PATH_INFO,REDIRECT_URL', 'url_html_suffix' => '', 'var_group' => 'g', 'var_module' => 'm', 'var_action' => 'a', 'var_ajax_submit' => 'ajax', 'var_pathinfo' => 's', 'var_url_params' => '_URL_', 'var_template' => 't', 'extends' => array('app_begin' => array(0 => 'CheckLang',),),));
G('loadTime');
Think::Start();